package com.ioc.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;


/**
 * @author cyt
 * @create 2020-07-29 下午 11:48
 */
public class LinuxCondition implements Condition {

    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 1 获得类加载器
        ClassLoader classLoader = context.getClassLoader();
        // 2 获得运行时候的环境
        Environment environment = context.getEnvironment();
        // 3 获得 bean的注解类
        BeanDefinitionRegistry registry = context.getRegistry();
        // 4 获得bean的工厂
        ConfigurableListableBeanFactory factory = context.getBeanFactory();

        String osname = environment.getProperty("os.name");
        if (osname.contains("Linux")) {
            return true;
        }
        return false;
    }
}
